using System;
using System.Collections.Generic;

namespace Lswweb.Domain
{
	public class ShoppingCartItem:IShoppingCartItem
	{
		private readonly int productId;
		private readonly string productName;
		private decimal unitPrice;
		private int quantity;
        private int unitWeight;
        private string img;
        private IDictionary<string, object> others;

        public ShoppingCartItem(int productId, string productName, string img,decimal unitPrice,int unitWeight, int quantity)
        {
            this.productId = productId;
            this.productName = productName;
            this.unitPrice = unitPrice;
            this.unitWeight = unitWeight;
            this.quantity = quantity;
            this.img = img;
            this.others = new Dictionary<string, object>();
        }

        public Int32 ProductId 
        {
            get { return this.productId; } 
        }

		public String ProductName
		{
            get { return this.productName; }
		}

		public Decimal UnitPrice
		{
            get { return this.unitPrice; }
            set { this.unitPrice = value; }
		}

		public Int32 Quantity
		{
            get { return this.quantity; }
            set
            {
                if (value > 0)
                    this.quantity = value;
                else
                    this.quantity = 0;
            }
		}

        public Decimal SubTotalPrice
        {
            get { return this.unitPrice * this.quantity; }
        }

        public IDictionary<string,object> Others 
        {
            get { return this.others; }
        }

        public string ProductImage
        {
            get { return this.img; }
        }

        public int UnitWeight
        {
            get { return this.unitWeight; }
        }

        public int SubTotalWeight
        {
            get { return this.unitWeight * this.quantity; }
        }

        #region override Equals and GetHashCode

        public override bool Equals(object obj)
        {
            if (obj == null && this == null)
                return true;

            if (obj == null)
                return false;

            if (obj.GetType() != this.GetType())
                return false;

            return ((ShoppingCartItem)obj).productId == this.ProductId;
        }

        public override int GetHashCode()
        {
            return this.productId.GetHashCode();
        }

        #endregion 
    }
}
